package leetCode.hw.string;

import java.util.List;

public class HJ17Solution implements HJ17 {

    /**
     * 利用异常处理机制完美解决
     * @param moveList
     * @return
     */
    @Override
    public int[] lastLocation(List<String> moveList) {
        int[] result = new int[2];
        for (String str : moveList) {
            if (str.length() > 1) {
                try {
                    switch (str.charAt(0)) {
                        case 'A':
                            result[0] -= Integer.parseInt(str.substring(1));
                            continue;
                        case 'D':
                            result[0] += Integer.parseInt(str.substring(1));
                            continue;
                        case 'W':
                            result[1] += Integer.parseInt(str.substring(1));
                            continue;
                        case 'S':
                            result[1] -= Integer.parseInt(str.substring(1));
                    }
                }catch(Exception ignored){}
            }
        }
        return result;
    }


}
